﻿
namespace System.Reflection
{
    public class Constructor<T>
    {
        // Fields
        private ConstructorInfo f_Info;
        private T f_Object;
        private bool f_Private;
        private Type[] f_Types;

        // Methods
        public Constructor(T o, bool Private = false, params Type[] Types)
        {
            Initialize(f_Object = o, Types, f_Private = Private);
        }

        // Properties
        public bool IsExist
        {
            get { return (f_Info != null); }
        }

        public T Object
        {
            get { return f_Object; }
            set { Initialize(f_Object = value, f_Types, f_Private); }
        }

        public bool Private
        {
            get { return f_Private; }
            set { Initialize(f_Object, f_Types, f_Private = value); }
        }

        public Type[] Types
        {
            get { return f_Types; }
            set { Initialize(f_Object, f_Types = value, f_Private); }
        }

        private void Initialize(T o, Type[] Types, bool Private)
        {
            f_Info =
                o.GetType().GetConstructor(
                    BindingFlags.Instance | (Private ? BindingFlags.NonPublic : BindingFlags.Public), null, Types, null);
        }
    }
}